<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      header {
        width: 200px;
        height: 200px;
      }
      .color {
        margin: 10px;
        width: 200px;
      }
    </style>
  </head>
  <main>
    <header id="color" style="background-color: rgb(54, 198, 54)"></header>
    红色:
    <input type="range" min="0" max="255" value="54" class="color" id="red" />
    <br />绿色:
    <input
      type="range"
      min="0"
      max="255"
      value="198"
      class="color"
      id="green"
    /><br />
    蓝色:
    <input type="range" min="0" max="255" value="54" class="color" id="blue" />
  </main>
  <script>
    var red = document.getElementById("red");
    var green = document.getElementById("green");
    var blue = document.getElementById("blue");
    var color = document.getElementById("color");

    red.addEventListener("input", function () {
      Color();
    });

    green.addEventListener("input", function () {
      Color();
    });

    blue.addEventListener("input", function () {
      Color();
    });

    function Color() {
      var r = red.value;
      var g = green.value;
      var b = blue.value;
      color.style.backgroundColor = `rgb(${r},${g},${b})`;
    }
  </script>
</html>
